export default {
	// 初始化事件
	formartData(time, fmt) {
		const nowTime = new Date(time);
		const timeObj = {
			YYYY: nowTime.getFullYear(),
			MM: (nowTime.getMonth() + 1 + '').padStart(2, '0'),
			dd: (nowTime.getDate() + '').padStart(2, '0'),
			HH: (nowTime.getHours() + '').padStart(2, '0'),
			mm: (nowTime.getMinutes() + '').padStart(2, '0'),
			ss: (nowTime.getSeconds() + '').padStart(2, '0')
		};
		for (const t in timeObj) {
			const ret = new RegExp('(' + t + ')').exec(fmt);
			if (ret) {
				fmt = fmt.replace(ret[1], timeObj[t]);
			}
		}
		return fmt;
	},

	// 处理大数字
	formartNum(val) {
		let num = 0;
		if (val > 9999 && val <= 99999999) {
			num = Math.round(val / 10000 * 10) / 10 + '万';
		} else if (val > 99999999) {
			num = Math.round(val / 100000000 * 10) / 10 + '亿';
		} else {
			num = val;
		}
		return num;
	},
	// 歌曲毫秒格式化处理 03:30
	formatSongTime(duration = 0) {
		duration = duration / 1000;
		const m = (Math.floor(duration / 60) + '').padStart(2, '0');
		const s = (Math.floor(duration % 60) + '').padStart(2, '0');
		return `${m}:${s}`;
	},
	// 评论时间格式化处理
	formatMsgTime(duration) {
		let result = '';
		const NOW = new Date();
		const PAST = new Date(duration);

		// 判断是当天的时间 显示格式 10：30
		if (NOW.toDateString() === PAST.toDateString()) {
			result = this.formartData(duration, 'HH:mm');
			// 时间为当年 显示月日 时间戳
		} else if (PAST.getFullYear() === NOW.getFullYear()) {
			result = this.formartData(duration, 'MM月dd日 HH:mm');
		} else {
			result = this.formartData(duration, 'yyyy年MM月dd日');
		}

		return result;
	}
};
